import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem } from '@/utils/storage.js'

Vue.use(Vuex)

const TOKEN_KEY = 'TOUTIAO_USER'
export default new Vuex.Store({
  state: {
    // token: null,
    // user: localStorage.getItem(TOKEN_KEY) ? JSON.parse(localStorage.getItem(TOKEN_KEY)) : null
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    // setToken (state, token) {
    //   state.token = token
    //   // localStorage.setItem('TOUTIAO_TOKEN', token)
    // },
    setUser (state, user) {
      state.user = user
      // localStorage.setItem(TOKEN_KEY, JSON.stringify(user))
      setItem(TOKEN_KEY, user)
    }
  },
  actions: {
  },
  modules: {
  }
})
